#include<iostream>
using namespace std;

template<class T>
struct AVLtree_node
{
    T _val; // 权值
    int _h; // 以该节点为根的子树的高度
    int _cnt;   // 值为_val的数的个数
    int _size;  // 以该节点为根的子树的大小

    AVLtree_node* _left;    // 左儿子
    AVLtree_node* _right;   // 右儿子
    AVLtree_node* _parent;  // 父节点
    AVLtree_node(const T& x = T(), AVLtree_node* parent = nullptr, AVLtree_node* left = nullptr, AVLtree_node* right = nullptr)
        :_val(x)
        ,_h(1)
        ,_cnt(1)
        ,_size(1)
        ,_left(left)
        ,_right(right)
        ,_parent(parent)
    {}
};

const int N = 1e6 + 1e5 + 10;
AVLtree_node<int> t[N];
int idx;

template<class T>
class AVLtree
{
    typedef AVLtree_node<T> node;
    typedef AVLtree_node<T>* node_ptr;
protected:
    node* _root = nullptr;

public:
    node* get_node(const T& val) {
        // return new node(val);
		t[idx]._val = val;
		t[idx]._cnt = t[idx]._size = t[idx]._h = 1;
		t[idx]._parent = t[idx]._left = t[idx]._right = nullptr;
        return &t[idx++];
    }

    void del_node(node* cur) {
        // delete cur;
    }

    // 找到返回权值为x的节点，否则返回x应该插入的位置的父节点
    node* find(const T& val)
    {
        node* p = nullptr;
        node* cur = _root;
        while(cur)
        {
            p = cur;
            if(val < cur->_val) cur = cur->_left;
            else if(val > cur->_val) cur = cur->_right;
            else return cur;
        }
        return p; 
    }

    bool insert(const T& val)
    {
        if(!_root) 
        {
            _root = get_node(val);
            return true;
        }
        node* cur = find(val);
        if(cur->_val == val)
            cur->_cnt++;
        else{
            node* p = cur;
            cur = get_node(val);
            cur->_parent = p;
            if(val < p->_val) p->_left = cur;
            else p->_right = cur;
        }
        // 平衡调整
        update(cur);
        return true;
    }
    
    bool erase(const T& val)
    {
        if(!_root) return false;
        node* cur = find(val);
        if(cur->_val == val)
        {
            cur->_cnt--;
            if(cur->_cnt != 0) update(cur);
            else{
                node* p = cur->_parent;
                // 1.叶子节点：直接删除
                if(!cur->_left && !cur->_right)
                {
                    if(!p) _root = nullptr; // 特判只有一个节点
                    else if(cur == p->_left) p->_left = nullptr;
                    else p->_right = nullptr;
                    del_node(cur);
                    update(p);
                }
                // 2.只有一个儿子：用儿子替代
                else if(!cur->_left || !cur->_right)
                {
                    node* child = cur->_left ? cur->_left : cur->_right;
                    if(!p) _root = child;   // 特判只有一个节点
                    else if(p->_left == cur) p->_left = child;
                    else p->_right = child;
                    child->_parent = p;
                    del_node(cur);
                    update(p);
                }
                // 3.有两个儿子: 用前驱替代，然后删除前驱
                else{
                    // 找前驱
                    node* pre = cur->_left;
                    node* pre_parent = cur;
                    while(pre->_right) 
                    {
                        pre_parent = pre;
                        pre = pre->_right;
                    }
                    // 交换，然后删除前驱节点
                    std::swap(cur->_val, pre->_val);
                    std::swap(cur->_cnt, pre->_cnt);
                    // 到这里pre必定没有右儿子
                    if(pre_parent->_left == pre) pre_parent->_left = pre->_left;
                    else pre_parent->_right = pre->_left;
                    if(pre->_left) pre->_left->_parent = pre_parent;
                    del_node(pre);
                    update(pre_parent);
                }
            }
            return true;
        }
        return false;
    }

    const T& get_prev(const T& val)
    {
        node* cur = find(val);
        if(cur->_val < val)
            return cur->_val;
        else 
            return get_prev(cur)->_val;
    }
    const T& get_next(const T& val)
    {
        node* cur = find(val);
        if(cur->_val > val)
            return cur->_val;
        else 
            return get_next(cur)->_val;
    }
    // 查询val的排名（查询有多少个数比 val 小，并且将得到的答案加一。注意val可能不在树中）
    int get_rank(const T& val)    
    {
        int res = 0;
        node* cur = _root;
        while(cur)
        {
            if(val < cur->_val)
                cur = cur->_left;
            else if(val == cur->_val)
            {
                res += size(cur->_left);
                break;
            } 
            else{
                res += size(cur->_left) + cur->_cnt;
                cur = cur->_right;
            }
        }
        return res + 1;
    }
    const T kth(int k)
    {
        node* cur = _root;
        while(cur)
        {
            if(k <= size(cur->_left))
                cur = cur->_left;
            else if(k <= size(cur->_left) + cur->_cnt)
                return cur->_val;
            else{
                k -= size(cur->_left) + cur->_cnt;
                cur = cur->_right;
            }
        }
        return -1;
    }

protected:
    int height(node* x) { return x ? x->_h : 0; }
    int size(node* x) { return x ? x->_size : 0; }
    void push_up(node* x) 
    { 
        if(!x) return;
        x->_h = max(height(x->_left), height(x->_right)) + 1;
        x->_size = size(x->_left) + size(x->_right) + x->_cnt;
    }

    //     |               |
    //     p               x
    //    / \             / \
    //   x   C   ====>   A   p
    //  / \                 / \
    // A   B               B   C
    void rotateR(node* p)
    {
        node* g = p->_parent;
        node* x = p->_left;
        p->_left = x->_right;
        if(x->_right) x->_right->_parent = p;

        x->_right = p;
        p->_parent = x;

        x->_parent = g;
        if(g){
            if(p == g->_left) g->_left = x;
            else g->_right = x;
        }
        push_up(p);
        push_up(x);
        if(_root == p) _root = x;
    }

    //     |               |
    //     p               x
    //    / \             / \
    //   x   C   <====   A   p
    //  / \                 / \
    // A   B               B   C
    void rotateL(node* x)
    {
        node* g = x->_parent;
        node* p = x->_right;
        x->_right = p->_left;
        if(p->_left) p->_left->_parent = x;

        p->_left = x;
        x->_parent = p;

        p->_parent = g;
        if(g){
            if(x == g->_left) g->_left = p;
            else g->_right = p;
        }
        push_up(x);
        push_up(p);
        if(_root == x) _root = p;
    }

    void balance(node* p)
    {
        int l = height(p->_left), r =height(p->_right);
        if(l > r)
        {
            int ll = height(p->_left->_left), lr = height(p->_left->_right);
            // LL型
            //     p
            //    /
            //   ●
            //  /
            // ●    
            if(ll >= lr) 
                rotateR(p);
            // LR型
            //     p
            //    /
            //   ●
            //    \ 
            //     ●
            else{
                rotateL(p->_left);
                rotateR(p);
            }
        }
        else{
            int rr = height(p->_right->_right), rl = height(p->_right->_left);
            // RR型
            //  p
            //   \
            //    ●
            //     \
            //      ●
            if(rr >= rl)
                rotateL(p);
            // RL型
            //  p
            //   \
            //    ●
            //    /
            //   ●
            else{
                rotateR(p->_right);
                rotateL(p);
            }
        }
    }

    void update(node* p)
    {
        while(p)
        {
            node* g = p->_parent;
            int l = height(p->_left), r =height(p->_right);
            if(abs(l - r) <= 1)
                push_up(p);
            else       // 平衡破坏，需旋转调整
                balance(p);
            p = g;
        }
    }
    
    node* get_prev(node* x)
    {
        if(!x) return nullptr;

        if(x->_left)
        {
            x = x->_left;
            while(x->_right)
                x = x->_right;
            return x;
        }
        else{
            node* p = x->_parent;
            while(p && x == p->_left)
            {
                x = p;
                p = p->_parent;
            }
            return p;
        }
    }
    node* get_next(node* x)
    {
        if(!x) return nullptr;

        if(x->_right)
        {
            x = x->_right;
            while(x->_left)
                x = x->_left;
            return x;
        }
        else{
            node* p = x->_parent;
            while(p && x == p->_right)
            {
                x = p;
                p = p->_parent;
            }
            return p;
        }
    }
};


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, op, x, last = 0, res = 0;
	AVLtree<int> t;
	cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        t.insert(a);
    }
    for(int i = 0; i < m; i++)
    {
        cin >> op >> x;
        x ^= last;
        if(op == 1) t.insert(x);
        else if(op == 2) t.erase(x);
        else{
            if(op == 3) last = t.get_rank(x);
            else if(op == 4) last = t.kth(x);
            else if(op == 5) last = t.get_prev(x);
            else last = t.get_next(x);
            res ^= last;
        }
    }
    cout << res;
    return 0;
}